<?php
session_start();
	include('../controller/functions.php');
	User::connection();

$userArr	= array('admin','teacher','student');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
	header("location:login_r.php");

}


?>

<!--lets get it -->
<? $topid = $_GET['cmsid'];

//topic query again
//loop it!
$topicQuery = mysql_query("SELECT * FROM tblcms WHERE cmsid = '$topid' ");
//eto n ang loop
	while($row  =  mysql_fetch_array($topicQuery)):
	$topicid = $row['cmsId'];
	$title 	 = $row['cmsTitle'];
	$content = $row['cmsContent'];
	$date 	 = $row['cmsDate'];
	$createby = $row['cmsEditor'];
	$createid = $row['cmsEditorBy'];
	$topiccat = $row['cmsType'];
	
	if($topiccat == 'home'):
		$catlink = 'viewHome';
		$catego = 'Home';
		//Filipino Section
		elseif($topiccat == 'about'):
		$catlink = 'viewAbout';
		$catego = 'About';
		//English Section
		elseif($topiccat == 'annouce'):
		$catlink = 'viewAnnouce';
		$catego = 'Annoucement';
		//Math Section
		elseif($topiccat == 'gallery'):
		$catlink = 'viewGallery';
		$catego = 'gallery';
		//Science Section
		elseif($topiccat == 'contact'):
		$catlink = 'viewContact';
		$catego = 'Contact';
		//Others Section

endif;
	endwhile;
	
	//who post 
	
	$postby = mysql_query("SELECT * FROM tbluser WHERE userid = '$createid' ");
	while($memberRow = mysql_fetch_array($postby)):
		$postedBy = $memberRow['userid'];
		$ava 	  = $memberRow['avatar'];
	endwhile;
	$numView+=1;
	mysql_query("UPDATE tblcms SET views = '$numView' WHERE topicid = '$topId'");
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>

	<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/front.css" type="text/css" charset="utf-8" />
    	<link type="text/css" href="../css/demo.css" rel="stylesheet" />
        <style type="text/css">

.cat{ font-family: Arial, Helvetica, sans-serif; color: #8DF5FE; font-size:16px;font-weight:bold;}

.label {font-family: Arial, Helvetica, sans-serif; color: #000; font-size:14px;}
a.title:link {font-family: Arial, Helvetica, sans-serif; color:#00CEC4; font-size:14px; font-weight:bold;}
a.title:visited{font-family: Arial, Helvetica, sans-serif; color:#00CEC4; font-size:14px; font-weight:bold;}
a.title:active{font-family: Arial, Helvetica, sans-serif; color:#00CEC4; font-size:14px; font-weight:bold;}
a.title:hover{font-family: Arial, Helvetica, sans-serif; color: #69CCFC; font-size:14px; text-decoration:underline; font-weight:bold;}

a.postedby:link {font-family: Arial, Helvetica, sans-serif; color: #00CEC4; font-size:12px;}
a.postedby:visited{font-family: Arial, Helvetica, sans-serif; color:#00CEC4; font-size:12px;}
a.postedby:active{font-family: Arial, Helvetica, sans-serif; color:#00CEC4; font-size:12px;}
a.postedby:hover{font-family: Arial, Helvetica, sans-serif; color: #69CCFC; font-size:12px; text-decoration:underline;}

.extra {font-family: Arial, Helvetica, sans-serif; color:#000000; font-size:12px;}


a.newtopic:link {font-family: Arial, Helvetica, sans-serif; color: #00886a; font-size:14px; font-weight:bold;}
a.newtopic:visited{font-family: Arial, Helvetica, sans-serif; color:#00886a; font-size:14px; font-weight:bold;}
a.newtopic:active{font-family: Arial, Helvetica, sans-serif; color:#00886a; font-size:14px; font-weight:bold;}
a.newtopic:hover{font-family: Arial, Helvetica, sans-serif; color: #00b48c; font-size:14px; font-weight:bold; text-decoration:underline;}

.mainbox { margin-top: 20px; }

a.siteloc:link{ font-family: Arial, Helvetica, sans-serif; color:#61770f; font-size:12px; text-decoration:none; text-align:left;}
a.siteloc:visited{font-family: Arial, Helvetica, sans-serif; color:#61770f; font-size:12px; text-decoration:none; text-align:left;}
a.siteloc:active{font-family: Arial, Helvetica, sans-serif; color:#61770f; font-size:12px; text-decoration:none; text-align:left;}
a.siteloc:hover{ font-family: Arial, Helvetica, sans-serif; color: #61770f; font-size:12px; text-decoration:underline; text-align:left;}
</style>
</head>
<body>

 <div id="page">
<div id="wrapper">
        
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
<!-- hide the client inquiries php-->
    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu.php');
	echo '</div>';
    echo '</div>';
	?>
    <div id="header_in"> <!--open header -->
    <p> </p>
    <? User::showUser(); ?>
    </div>
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
        <div id="chef_ind"> <!--open chef -->
        <div id="welcome"> <!--open welcome -->
               <!-- <h2 class="guilded"></h2> -->
        </div> <!--close welcome-->

<? echo '<p class="more">';
echo '';
 
   require('sideBar.php');
    
echo'</p>';
?>

        </div>
        
      </div><!--close left -->
    

          <h2>CMS</h2>
            <div class="desriptionHeader"> <!--open right-->
       <div class="post"><!--open booking -->
        

	
    <table width="630" border="0">
	<tr>
    	<td colspan="6">
	<a class="siteloc" href="cms.php">CMS</a> &ndash;&gt; <a class="siteloc" href="<? print $catlink; ?>.php"><? print $catego; ?></a> &ndash;&gt; <a class="siteloc" href="viewtopic.php?topicid=<? print $topicid; ?>"><? print $title; ?></a>
    	</td>
    </tr>
<tr>
		<td align="left" background="catbg.png" colspan="5" class="cat"><? print $title; ?></td>
    </tr>
                      <tr>
                      <td valign="top" width="12%" rowspan="6">
                      <a class="postedby" href="userprofile.php?userid=<? print $postedbyid; ?>"><? print $postedby; ?></a><br /></td>
                      </tr>

                      <tr>
                        <td width="58%" class="extra">Title: <? print $title; ?></td><td width="30%" align="right" class="extra"><? print $date; ?></td>
					</tr>
                      <tr>
                        <td colspan="2" height="1">

                        </td>
                      </tr>

                      <tr>
                        <td colspan="2">
                          <? print $topiccontent; ?>
                        </td>
                      </tr>
                      <tr>
                      <td align="right" colspan="2">
                      <?
                      $userid = $_SESSION['userid'];
	  
					  ?>&nbsp;
                      </td>
                      </tr>
</table>

<hr width="630" />

<?


$replyquery = mysql_query("SELECT * from tblfrreply WHERE topicid = '$topicid' ORDER BY replyid ASC ");
	while($row2 = mysql_fetch_array($replyquery))
		{
		$replyid = $row2['replyid']; 
		$replycontent = $row2['replycontent']; 
		$replytime = $row2['replytime'];
		$replyby = $row2['replyby'];
		$replybyid = $row2['replybyid'];
		
		
		$replybyav = mysql_query("SELECT * from tbluser WHERE userid = '$replybyid' ");
			while($reprow = mysql_fetch_array($replybyav))
		{
			$replierid = $reprow['user'];
			$repavatar = $reprow['avatar'];
		}
		
		
		print '
		<table width="700" border="0">
		<tr>
                      <td valign="top" width="13%" rowspan="6">
                      <a class="postedby" href="userprofile.php?userid='.$replybyid.'">'.$replyby.'</a><br />
                      <img src="avatar/'.$repavatar.'" width="100" height="100" border="0" /></td>
                      </tr>

                      <tr>
                        <td class="extra">Title: '.$title.'</td><td width="30%" align="right" class="extra">'.$replytime.'</td>
					</tr>
                      <tr>
                        <td colspan="2" height="1">
                          &nbsp;
                        </td>
                      </tr>

                      <tr>
                        <td colspan="2">
                          '.$replycontent.'
                        </td>
                      </tr>
					  <tr>
                        <td align="right" colspan="2">';
			
			
			if($_SESSION['user']=='admin')
			
			{
				print '
				
				<a href="editreply.php?topicid='.$cmsid.'" class="otherlink">Edit</a>&nbsp; 
				
				';
			
			
				print '
				
				<a href="replydelete.php?topicid='.$topid.'&replyid='.$replyid.'" class="otherlink">Delete</a>
				
				';
			
			}
			print '&nbsp;
						</td>
                    </tr>
				</table>
				<hr width="700" />
			
			';
                        
	
			/**/
		}



?>                
		
        
      
        </div>
  </div><!--close booking -->
   </div><!--close desc -->
   
          
     				
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 <?php 
	  echo '<div id="footer">';
     include('footer.php');
      echo '</div>';	
	  ?>

    </div><!-- close body-->
</div><!-- close page-->


</body>
</html>
